from django.shortcuts import render
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets
from rest_framework.filters import SearchFilter
from rest_framework.pagination import PageNumberPagination

from member.filter import MemberFilter
from member.models import Platform, Member
from member.serializers import PlatformSerializer, MemberSerializer


# Create your views here.


class Page(PageNumberPagination):
    page_size = 2
    page_query_param = 'page'
    page_size_query_param = 'size'


class PlatformView(viewsets.ModelViewSet):
    queryset = Platform.objects.all()
    serializer_class = PlatformSerializer

class MemberView(viewsets.ModelViewSet):
    queryset = Member.objects.all()
    serializer_class = MemberSerializer
    pagination_class = Page
    filterset_class = MemberFilter
    filter_backends = [DjangoFilterBackend,SearchFilter]
    search_fields = ['name','phone','identity','card','platform_name']